﻿using ServerListerner.Enums;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace ServerListerner.Helper
{
    internal static class ServerEntry
    {
        internal static T? StartConnection<T>(object[] obj) where T : class
        {
            Type type = typeof(T);
            Assembly assembly = Assembly.GetExecutingAssembly();
            var Types = assembly.GetTypes().Where(s => !s.FullName.StartsWith(nameof(System))
            && !s.FullName.StartsWith(nameof(Microsoft)) &&
             !s.FullName.ToLower().StartsWith("netstandard") && !s.IsAbstract && !s.IsInterface && s != type &
             s.GetInterface(type.Name) != null).FirstOrDefault();
            if (Types == null)
                return default(T);
            if (obj == null)
                return (T)Activator.CreateInstance(Types);
            return (T)Activator.CreateInstance(Types, obj);


        }
    }
    public class ServerConnect
    {
        protected T? StartConnection<T>(object[] obj) where T : class
        {
            Type type = typeof(T);
            Assembly assembly = Assembly.GetExecutingAssembly();
            var Types =  assembly.GetTypes().Where(s=>!s.FullName.StartsWith(nameof(System))
            && !s.FullName.StartsWith(nameof(Microsoft)) &&
             !s.FullName.ToLower().StartsWith("netstandard")&&!s.IsAbstract&&!s.IsInterface&&s!= type&
             s.GetInterface(type.Name)!=null).FirstOrDefault();
            if(Types==null)
                return default(T);
            if(obj==null)
                return (T)Activator.CreateInstance(Types);
            return (T)Activator.CreateInstance(Types, obj);

           
        }
    }
}
